include("shared.lua")

function ENT:Initialize()
end

function ENT:Draw()
	self.Entity:DrawModel()
end

function ENT:Think()
end

/*--------------------------------------------	
Shop Menu GUI
--------------------------------------------*/
function ShopMenu(handle, id, encoded, decoded )
	local WeaponTable = decoded.weapons
	local AmmoTable = decoded.ammo
	local ClientClass = LocalPlayer():GetPlayerClass()
	
	
	local DermaPanel = vgui.Create( "DFrame" )
	DermaPanel:SetPos( (ScrW() / 2 )- 175, (ScrH() / 2)- 167 )
	DermaPanel:SetSize( 291, 335 )
	DermaPanel:SetTitle( "Cash Shop" )
	DermaPanel:SetVisible( true )
	DermaPanel:SetDraggable( true ) -- Draggable by mouse?
	DermaPanel:ShowCloseButton( true ) -- Show the close button?
	DermaPanel:MakePopup()
	 
	local PropertySheet = vgui.Create( "DPropertySheet", DermaPanel )
	PropertySheet:SetPos( 5, 30 )
	PropertySheet:SetSize( 281, 300 )
	 
	 /*--------------------------------------------	
	 Weapons Panel
	 --------------------------------------------*/
	local WeaponPanel = vgui.Create( "DPanelList", DermaPanel )
	WeaponPanel:SetPos( 0, 0 )
	WeaponPanel:SetSize( 281, 300 )
	WeaponPanel:SetSpacing( 5 ) -- Spacing between items
	WeaponPanel:EnableVerticalScrollbar( true ) -- Allow scrollbar if you exceed the Y axis
	WeaponPanel:EnableHorizontal(true)
	WeaponPanel.Paint = function() -- Paint function
		surface.SetDrawColor( 50, 50, 50, 0)
		surface.DrawRect( 0, 0, WeaponPanel:GetWide(), WeaponPanel:GetTall() ) -- Draw the rect
	end
	
	--only displays weapons your class can use, fuck yea
	local PlayerClass =ClientClass.RawName
	for i,v in ipairs(WeaponTable) do
		for _,v in pairs(WeaponTable[i]['allowed']) do
			if v == PlayerClass then
					local Icon = vgui.Create( "SpawnIcon")
					Icon:SetModel((WeaponTable[i]['model']))
					Icon:SetToolTip(WeaponTable[i]['name'].." $"..tostring(WeaponTable[i]['price']))
						 function Icon:DoClick()
							   datastream.StreamToServer( "PurchaseWeapon", { ["table"] = WeaponTable[i],["string"] = ClientClass.RawName });
						  end
					WeaponPanel:AddItem( Icon )
			end
		end
	end
	
	/*--------------------------------------------	
	 Ammo Panel
	 --------------------------------------------*/ 
	local AmmoPanel = vgui.Create( "DPanelList", DermaPanel )
	AmmoPanel:SetPos( 0, 0 )
	AmmoPanel:SetSize( 281, 300 )
	AmmoPanel:SetSpacing( 5 ) -- Spacing between items
	AmmoPanel:EnableVerticalScrollbar( true ) -- Allow scrollbar if you exceed the Y axis
	AmmoPanel:EnableHorizontal(true)
	AmmoPanel.Paint = function() -- Paint function
		surface.SetDrawColor( 50, 50, 50, 0)
		surface.DrawRect( 0, 0, AmmoPanel:GetWide(), AmmoPanel:GetTall() ) -- Draw the rect
	end
	
	--only displays ammo your class can use
	local PlayerClass =ClientClass.RawName
	for i,v in ipairs(AmmoTable) do
		for _,v in pairs(AmmoTable[i]['allowed']) do
			if v == PlayerClass then
					local Icon = vgui.Create( "SpawnIcon")
					Icon:SetModel((AmmoTable[i]['model']))
					Icon:SetToolTip(AmmoTable[i]['name'].." $"..tostring(AmmoTable[i]['price']).." per bullet")
						 function Icon:DoClick()
							   datastream.StreamToServer( "PurchaseAmmo", { ["bought"] = AmmoTable[i],["class"] = ClientClass.RawName, ["max"] = ClientClass.MaxAmmo} );
						  end
					AmmoPanel:AddItem( Icon )
			end
		end
	end
	
	/*--------------------------------------------	
	 Add Tabls
	 --------------------------------------------*/
	PropertySheet:AddSheet( "Weapons", WeaponPanel, "gui/silkicons/bomb", false, false, "Buy some guns" )
	PropertySheet:AddSheet( "Ammo", AmmoPanel, "gui/silkicons/box", false, false, "Buy some guns" )
end

datastream.Hook( "ShopMenu", ShopMenu );